# -*- coding:utf-8 -*-
import bisect
import random
import time

# 操作复杂度 O(log(n))


def cal_time(func):  # 装饰器
    def wrapper(*args, **kwargs):
        t1 = time.time()
        result = func(*args, **kwargs)
        t2 = time.time()
        print("running time:",func.__name__, t2 - t1)
        return result
    return wrapper


@cal_time
def bisect_insert():
    random.seed(1)
    l = []
    for i in range(1, 20):
        r = random.randint(1, 100)
        position = bisect.bisect(l, r)  # 返回index
        bisect.insort(l, r)   # 等同于insort_right 右侧插入
        print('%3d  %3d' % (r, position), l)

